package org.hiucung.hlsdownloader

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.XXPermissions
import com.hjq.permissions.permission.PermissionLists
import com.hjq.permissions.permission.base.IPermission

import org.hiucung.hlsdownloader.ui.screens.MainScreen

/**
 * @Classname MainActivity
 * @Description HLS下载器主页
 * M38U测试链接：https://upyun.luckly-mjw.cn/Assets/media-source/example/media/index.m3u8
 * @Date 2025/8/21 14:46
 * @Created by Kicc
 */
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            MaterialTheme {
                MainScreen()
            }
        }
        XXPermissions.with(this)
            // 申请多个权限
            .permission(PermissionLists.getManageExternalStoragePermission())
            // 设置不触发错误检测机制（局部设置）
            //.unchecked()
            .request(object : OnPermissionCallback {

                override fun onResult(grantedList: MutableList<IPermission>, deniedList: MutableList<IPermission>) {
                    val allGranted = deniedList.isEmpty()
                    if (!allGranted) {
                        // 判断请求失败的权限是否被用户勾选了不再询问的选项
                        // 在这里处理权限请求失败的逻辑
                        // ......
                        return
                    }
                    // 在这里处理权限请求成功的逻辑
                    // ......


                }
            })
    }
}